package com.itheima.service;

import com.itheima.dao.BaseStudentDao;
import com.itheima.dao.OtherStudentDao;
import com.itheima.dao.StudentDao;
import com.itheima.domain.Student;
import com.itheima.factory.StudentFactory;

import java.util.ArrayList;

/*
学生业务处理类
增
删
改
查

1.业务判断
2.连接controller 和  dao

 */
public class StudentService {
   // private OtherStudentDao studentDao = new OtherStudentDao();
private BaseStudentDao studentDao= StudentFactory.getStudentDao();
    public void addStudent(Student student) {
        //调用dao 完成新增
        studentDao.addStudent(student);
    }

    public ArrayList<Student> findAllStudents() {
        //ArrayList<Student> list= studentDao.findAllStudents();
        return studentDao.findAllStudents();
    }
    //判断这个学号在集合中是否存在
    public boolean isExist(String sid) {
        //调用dao获取所有学生
        ArrayList<Student> list = studentDao.findAllStudents();
        //遍历集合 获取每一个学生
        for (int i = 0; i < list.size(); i++) {
            Student student = list.get(i);
            //比较学生的学号和录入的学号是否相同
            if(student.getSid().equals(sid)){
                //相同  返回存在
                return true;
            }
        }
        return false;
    }

    public void deleteStudent(String sid) {
        studentDao.deleteStudent(sid);

    }

    public void updateStudent(String sid, Student student) {
        studentDao.updateStudent(sid,student);
    }
}
